home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / Internet Developer Demos / Bare Bones Software Goodies / PopupFuncs 2.8.1 / xPop ƒ / winsize.c < prev    next >
C/C++ Source or Header  |  1992-07-05  |  3KB  |  128 lines

  1. #include    <SetupA4.h>
  2. #include    "xpop.h"
  3. #include    <stdio.h>
  4.  
  5. /* a simple xpop to change the default width of ThinkC's windows */
  6. /* works only with version 5.0.2 */
  7. /* most useful when using a large screen, where the factory default is too wide */
  8. /* defaults to 500 pixels wide (a little narrower than the factory setting) */
  9. /* can be changed by selecting the width you want, than choosing the xpop */
  10. /* eric slosser */
  11. /* please feel free to improve this hack */
  12.  
  13. enum    { kUnknown, kUnsurround, kSurround };
  14.  
  15. XPopRecPtr        gPopRec;
  16.  
  17. void    DoInit(void);
  18. void    DoClose(void);
  19. void    DoFOpen(void);
  20. void    DoFClose(void);
  21. void    DoQuery(void);
  22. void    DoIt(void);
  23.  
  24. void    SetIt( short w );
  25.  
  26. pascal void main( XPopRecPtr paramPtr)
  27.     {
  28.     RememberA0();
  29.     SetUpA4();
  30.     
  31.     gPopRec = paramPtr;
  32.     switch (paramPtr->message) {
  33.         case    xpop_init:    DoInit();        break;
  34.         case    xpop_close:    DoClose();        break;
  35.         case    xpop_fopen:    DoFOpen();        break;
  36.         case    xpop_fclose:    DoFClose();        break;
  37.         case    xpop_query:    DoQuery();        break;
  38.         case    xpop_doit:    DoIt();            break;
  39.         }
  40.     RestoreA4();
  41. }    /* main */
  42.  
  43. /*---------------*/
  44. void    DoInit(void)
  45. {
  46.     InitRecPtr        initStuff;
  47.     SelectionRecPtr    selection;
  48.     Handle            intH;
  49.     
  50.     selection = (SelectionRecPtr) gPopRec->param;
  51.  
  52.     if ( selection->environment==kTHINK ) {
  53.         intH = GetResource('wWid',0);
  54.         if ( intH ) {
  55.             SetIt( **((int**)intH) );
  56.             }
  57.         else {
  58.             intH = NewHandle(sizeof(int));
  59.             **((int**)intH) = 500;
  60.             AddResource(intH,'wWid',0,"");
  61.             }
  62.         }
  63.     initStuff = (InitRecPtr) NewPtr(sizeof(InitRec));
  64.     if ( initStuff!=NIL ) {
  65.         initStuff-> version = 1;
  66.         initStuff-> language = -1;    /* all languages */
  67.         initStuff-> writes = true;
  68.         initStuff-> sensitive = false;
  69.         initStuff-> getFileMsgs = false;
  70.         initStuff-> selStuff = kNeedSelection;
  71.         initStuff-> environment = (1<< kTHINK);        
  72.         }
  73.     gPopRec->result = (long) initStuff;
  74. }
  75. /*---------------*/
  76. void    DoClose(void)
  77. {}
  78. /*---------------*/
  79. void    DoFOpen(void)
  80. {}
  81. /*---------------*/
  82. void    DoFClose(void)
  83. {}
  84. /*---------------*/
  85. void    DoQuery(void)
  86. {
  87.     SelectionRecPtr    selection;
  88.  
  89.     gPopRec->result = (long) "\pWinSize(";
  90.     
  91.     selection = (SelectionRecPtr) gPopRec->param;
  92.     if ( selection->selEnd == selection->selStart ||
  93.          selection->hText == NIL )
  94.         return;
  95.  
  96.     gPopRec->result = (long) "\pWinSize";
  97. }
  98. /*---------------*/
  99. void    DoIt(void)
  100. {
  101.     SelectionRecPtr    selection;
  102.     PostDoRecPtr    rec;
  103.     long            width;
  104.     Handle            intH;
  105.     
  106.     selection = (SelectionRecPtr) gPopRec->param;
  107.     StringToNum(c2pstr( *selection->hText ),&width);
  108.     SetIt( width );
  109.     intH = GetResource('wWid',0);
  110.     **((int**)intH) = width;
  111.     ChangedResource( intH );
  112.     
  113.     rec = (PostDoRecPtr) NewPtr(sizeof(PostDoRec));
  114.     if ( rec ) {
  115.         rec->version = 1;
  116.         rec->paste = false;
  117.         }
  118.     gPopRec->result = (long) rec;
  119. }
  120. /*---------------*/
  121. void    SetIt( short w )
  122. {
  123.     asm {
  124.         movea.l    0x904,a0
  125.         //move.w    w,-0x4e70(a0)    /* 5.0.1? */
  126.         move.w    w,-0x5cfc(a0)    /* 5.0.2 */
  127.         }
  128. }